%Down biased (H reference local) transfn 
% Referece Sims et al 1971  Geophysics
% importance - the simple matrix notations l
% uses the matrix notations
%CHECKED WITH GEOTOOLS OK 30.4.3
% latest date 30.4.3
%#eml
function[tf]=tf_dn(SPMatrix),


% the following block is commented assuming that 
% SPMatrix will always be a matrix March 23, 2011
% 
% if isstruct(SPMatrix) == 1, % for structur arryay
%    nfreq = length(SPMatrix.spectra); % in momentory lapse of common sense i adopted structure
%       for i = 1:nfreq,
%    	SPM(i,:,:) = SPMatrix.spectra(i).data;
%    end;
%    clear SPMatrix;
%    SPMatrix=SPM;
% end;
% 

A = size(SPMatrix);



if length(A) == 2,
   data(:,:)=SPMatrix;
   [EH,HH]=getmat(data);
   Z = EH/HH; % inverse of admittance = impedance
   tf(1)=Z(1,2);% boring !! but i have to do this
   tf(2)=Z(2,1);
   tf(3)=Z(1,1);
   tf(4)=Z(2,2);
elseif length(A)==3,
   for i =1:A(1),
      data(:,:)=SPMatrix(i,:,:);
      [EH,HH]=getmat(data);
   Z = EH/HH;
   tf(i,1)=Z(1,2);% boring !! but i have to do this
   tf(i,2)=Z(2,1);
   tf(i,3)=Z(1,1);
   tf(i,4)=Z(2,2);
end;
 
end;
tf(:,5:8)=0; %variance need to be added 20.4.3
   
   
   
%helper function


function[EH,HH]=getmat(data),

j = sqrt(-1);

HxHx = data(1,1);
HyHy = data(2,2);

HxHy = data(2,1) - j*data(1,2);
HyHx = conj(HxHy);
HxEx = data(4,1) - j*data(1,4);
ExHx = conj(HxEx);
HxEy = data(5,1) - j*data(1,5);
EyHx = conj(HxEy);
ExHy = data(4,2) + j*data(2,4);
EyHx = conj(HxEy);
ExHy = data(4,2) + j*data(2,4);
HyEy = data(5,2) - j*data(2,5);
EyHy = conj(HyEy);


EH=[ExHx ExHy;EyHx EyHy];
HH=[HxHx HxHy;HyHx HyHy];

